if [[ "$(uname)" == "Darwin" ]]; then
  SHADERC="../tools/mac/shaderc"
else
  SHADERC="../tools/windows/shaderc.exe"
fi

function compile_vertex_windows() {
  OUTPUT="../src/core/shader/hlsl/$3"
  $SHADERC -f "$1" --varyingdef "$2" -o $OUTPUT -i ./include --platform windows -p s_5_0 --type vertex --bin2c "$4"
  ./fix-header.sh $OUTPUT $4
}
function compile_fragment_windows() {
  OUTPUT="../src/core/shader/hlsl/$3"
  $SHADERC -f "$1" --varyingdef "$2" -o $OUTPUT -i ./include --platform windows -p s_5_0 --type fragment --bin2c "$4"
  ./fix-header.sh $OUTPUT $4
}
function compile_vertex_mac() {
  OUTPUT="../src/core/shader/metal/$3"
  $SHADERC -f "$1" --varyingdef "$2" -o $OUTPUT -i ./include --platform osx -p metal --type vertex --bin2c "$4"
  ./fix-header.sh $OUTPUT $4
}
function compile_fragment_mac() {
  OUTPUT="../src/core/shader/metal/$3"
  $SHADERC -f "$1" --varyingdef "$2" -o $OUTPUT -i ./include --platform osx -p metal --type fragment --bin2c "$4"
  ./fix-header.sh $OUTPUT $4
}
function compile_vertex_android() {
  OUTPUT="../src/core/shader/glsl/$3"
  $SHADERC -f "$1" --varyingdef "$2" -o $OUTPUT -i ./include --platform android -p 100_es --type vertex --bin2c "$4"
  ./fix-header.sh $OUTPUT $4
}
function compile_fragment_android() {
  OUTPUT="../src/core/shader/glsl/$3"
  $SHADERC -f "$1" --varyingdef "$2" -o $OUTPUT -i ./include --platform android -p 100_es --type fragment --bin2c "$4"
  ./fix-header.sh $OUTPUT $4
}

function windows() {
  compile_vertex_windows minimum/vs_minimum.sc minimum/varying.def.sc vs_minimum.h VS_MINIMUM
  compile_fragment_windows minimum/fs_minimum.sc minimum/varying.def.sc fs_minimum.h FS_MINIMUM
  compile_vertex_windows standard/vs_standard.sc standard/varying.def.sc vs_standard.h VS_STANDARD
  compile_fragment_windows standard/fs_standard.sc standard/varying.def.sc fs_standard.h FS_STANDARD
}
function mac() {
  compile_vertex_mac minimum/vs_minimum.sc minimum/varying.def.sc vs_minimum.h VS_MINIMUM
  compile_fragment_mac minimum/fs_minimum.sc minimum/varying.def.sc fs_minimum.h FS_MINIMUM
  compile_vertex_mac standard/vs_standard.sc standard/varying.def.sc vs_standard.h VS_STANDARD
  compile_fragment_mac standard/fs_standard.sc standard/varying.def.sc fs_standard.h FS_STANDARD
  compile_vertex_mac instancing/vs_instancing.sc instancing/varying.def.sc vs_instancing.h VS_INSTANCING
  compile_fragment_mac instancing/fs_instancing.sc instancing/varying.def.sc fs_instancing.h FS_INSTANCING
}
function android() {
  compile_vertex_android minimum/vs_minimum.sc minimum/varying.def.sc vs_minimum.h VS_MINIMUM
  compile_fragment_android minimum/fs_minimum.sc minimum/varying.def.sc fs_minimum.h FS_MINIMUM
  compile_vertex_android standard/vs_standard.sc standard/varying.def.sc vs_standard.h VS_STANDARD
  compile_fragment_android standard/fs_standard.sc standard/varying.def.sc fs_standard.h FS_STANDARD
}

if [ "$1" == "windows" ]; then
  windows
elif [ "$1" == "mac" ]; then
  mac
elif [ "$1" == "android" ]; then
  android
elif [ "$1" == "all" ]; then
  windows
  mac
  android
else
  echo "Error: must specified platform [windows/mac/android/all]"
  exit -1
fi